package vanScheduling;

import db.PermissionDAO;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class Permission {

    private int id;
    private String permissionLevel;

    //<editor-fold desc="Constructors">
    public Permission() {
    }

    public Permission(int id, String permissionLevel) {
        this.id = id;
        this.permissionLevel = permissionLevel;
    }
    //</editor-fold>

    //<editor-fold desc="Getters and Setters">
    public int getId() {
        return id;
    }

    public String getPermissionLevel() {
        return permissionLevel;
    }

    public void setPermissionLevel(String permissionLevel) {
        this.permissionLevel = permissionLevel;
    }
    //</editor-fold>

    //<editor-fold desc="Editable Driver">
    private static Permission editablePermission;
    public void setEditableUser (Permission permission) {
        editablePermission = permission;
    }

    public Permission getEditablePermission() {
        return editablePermission;
    }

    public String editPermission() {
        FacesContext fc = FacesContext.getCurrentInstance();
        setEditableUser((Permission) fc.getExternalContext().getRequestMap().get("permission"));
        return "editPermission";
    }
    //</editor-fold>

    //<editor-fold desc="CRUD Methods">
//    public String addPermission() {
//        if (PermissionDAO.addUser(this)) {
//            return "permissionList"; //TODO - Forward to time slots
//        } else {
//            return "permissionAddFailure";
//        }
//    }
//
//    public String deleteUser() {
//        if (PermissionDAO.deletePermission(this)) {
//            return "userList";
//        } else {
//            return "userDeleteFailure";
//        }
//    }
//
    public List<Permission> getPermissions() {
        return PermissionDAO.getPermissions();
    }
//
//    public String saveUser() {
//        if (PermissionDAO.savePermission(this)) {
//            editablePermission = null;
//            return "userList";
//        } else {
//            return "userSaveFailure";
//        }
//    }
//    //</editor-fold>

    @Override
    public String toString() {
        return this.permissionLevel;
    }
}
